<template>
	<view class="userMessage">
		<myHead text_right="跳过" :right="true" :isReturn="false" @clickReturn="clickReturn" @clickRight="clickRight" />
		<view class="steps">
			<view class="headerTitle">
				邀请你填写在线简历
			</view>
			<u-steps :current="current" dot activeColor="#3476FE" inactiveColor="#C4C9D2">
				<u-steps-item title="基本信息" style="color: #3476FE;">
				</u-steps-item>
				<u-steps-item title="求职意向"></u-steps-item>
				<u-steps-item title="教育经历"></u-steps-item>
				<u-steps-item title="工作经历"></u-steps-item>
			</u-steps>
		</view>
		<view class="contentBox">
			<Basics :user.sync="Basics" v-if="current===0" />
			<JobIntention :user.sync="JobIntention" v-if="current===1" ref="JobIntention" />
			<Dducation :user.sync="Dducation" v-if="current===2" />
			<professional :user.sync="professional" v-if="current===3" ref="professional" />
		</view>
		<view class="bts">
			<u-button type="primary" text="下一步" @click="xiayibu"></u-button>
		</view>
	</view>
</template>

<script>
	import Basics from '@/pages/views/packageB/userMessage/tem/Basics.vue'
	import JobIntention from '@/pages/views/packageB/userMessage/tem/JobIntention.vue'
	import Dducation from '@/pages/views/packageB/userMessage/tem/Dducation.vue'
	import professional from '@/pages/views/packageB/userMessage/tem/professional.vue'
	import {
		watch
	} from "vue"

	export default {
		data() {
			return {
				current: 0,
				Basics: {
					CurrentRole: 0,
					Sex: 1,
					Name: ''
				},
				JobIntention: {
					WorkType: 0
				},
				Dducation: {},
				professional: {
					Tags: []
				},
				ResumeId: '444929912340613', //简历id
			};
		},
		methods: {
			clickReturn() {
				if (this.current != 0) {
					this.current--
				}
			},
			// 跳过
			clickRight() {
				uni.switchTab({
					url: "/pages/Home/index",
				});
			},
			xiayibu() {
				if (this.current === 0) {
					if (this.Basics.CurrentRole === '' || this.Basics.CurrentRole === undefined) {
						uni.$u.toast("请选择当前身份")
						return
					}
					if (this.Basics.Sex === '' || this.Basics.Sex === undefined) {
						uni.$u.toast("请选择性别")
						return
					}
					if (this.Basics.Name === '' || this.Basics.Name === undefined) {
						uni.$u.toast("请输入姓名")
						return
					}
					if (this.Basics.Address === '' || this.Basics.Address === undefined) {
						uni.$u.toast("请选择居住地址")
						return
					}
					if (this.Basics.Birthday === '' || this.Basics.Birthday === undefined) {
						uni.$u.toast("请选择生日")
						return
					}
					if (this.Basics.StartWorkDate === '' || this.Basics.StartWorkDate === undefined) {
						uni.$u.toast("请选择参加工作时间")
						return
					}
					if (this.Basics.CurrentStatus === '' || this.Basics.CurrentStatus === undefined) {
						uni.$u.toast("请选择求职状态")
						return
					}
					// 基础信息
					this.$http.huirc
						.save_resume(this.Basics).then(res => {
							if (res.Success) {
								console.log(res);
								this.ResumeId = res.Result.Id
								this.current++
							}
						})
				} else if (this.current === 1) {
					if (this.JobIntention.WorkType === '' || this.JobIntention.WorkType === undefined) {
						uni.$u.toast("请选择求职类型")
						return
					}
					if (this.JobIntention.PositionName === '' || this.JobIntention.PositionName === undefined) {
						uni.$u.toast("请选择期望职位")
						return
					}
					if (this.JobIntention.IndustryTitles === '' || this.JobIntention.IndustryTitles === undefined) {
						uni.$u.toast("请选择期望行业")
						return
					}
					if (this.JobIntention.PcaAddress === '' || this.JobIntention.PcaAddress === undefined) {
						uni.$u.toast("请选择期望城市")
						return
					}
					if (!this.JobIntention.Negotiable) {
						if (this.JobIntention.MinWage === '' || this.JobIntention.MinWage === undefined) {
							uni.$u.toast("请选择期望薪资")
							return
						}
					}
					// 求职意向
					console.log({
						...this.JobIntention,
						ResumeId: this.ResumeId
					});
					this.$http.huirc
						.save_jobexpect({
							...this.JobIntention,
							ResumeId: this.ResumeId
						}).then(res => {
							if (res.Success) {
								console.log(res)
								this.JobIntention.Id = res.Result.Id
								this.current++
							}
						})
				} else if (this.current === 2) {
					console.log(this.Dducation);
					if (this.Dducation.EduDegree === '' || this.Dducation.EduDegree === undefined) {
						uni.$u.toast("请选择最高学历")
						return
					} else if (this.Dducation.EduDegree < 3) {
						this.$http.huirc
							.save_educationexp({
								EduDegree: this.Dducation.EduDegree,
								ResumeId: this.ResumeId
							}).then(res => {
								if (res.Success) {
									this.Dducation.Id = res.Result.Id
									this.current++
								}
							})
					} else if (this.Dducation.EduDegree < 5) {
						if (this.Dducation.EduType === '' || this.Dducation.EduType === undefined) {
							uni.$u.toast("请选择是否统招")
							return
						}
						if (this.Dducation.SchoolName === '' || this.Dducation.SchoolName === undefined) {
							uni.$u.toast("请输入学校名称")
							return
						}
						if (this.Dducation.Major === '' || this.Dducation.Major === undefined) {
							uni.$u.toast("请输入专业名称")
							return
						}
						if (this.Dducation.StartDate === '' || this.Dducation.StartDate === undefined) {
							uni.$u.toast("请选择在校时间")
							return
						}
						if (this.Dducation.EndDate === '' || this.Dducation.EndDate === undefined) {
							uni.$u.toast("请选择在校时间")
							return
						}
						let da = JSON.parse(JSON.stringify(this.Dducation))
						delete da.Academic
						// 教育经历
						this.$http.huirc
							.save_educationexp({
								...da,
								ResumeId: this.ResumeId
							}).then(res => {
								if (res.Success) {
									this.Dducation.Id = res.Result.Id
									this.current++
								}
							})
					} else {
						if (this.Dducation.EduType === '' || this.Dducation.EduType === undefined) {
							uni.$u.toast("请选择是否统招")
							return
						}
						if (this.Dducation.Academic === '' || this.Dducation.Academic === undefined) {
							uni.$u.toast("请选择学位证书")
							return
						}
						if (this.Dducation.SchoolName === '' || this.Dducation.SchoolName === undefined) {
							uni.$u.toast("请输入学校名称")
							return
						}
						if (this.Dducation.Major === '' || this.Dducation.Major === undefined) {
							uni.$u.toast("请输入专业名称")
							return
						}
						if (this.Dducation.StartDate === '' || this.Dducation.StartDate === undefined) {
							uni.$u.toast("请选择在校时间")
							return
						}
						if (this.Dducation.EndDate === '' || this.Dducation.EndDate === undefined) {
							uni.$u.toast("请选择在校时间")
							return
						}
						// 教育经历
						this.$http.huirc
							.save_educationexp({
								ResumeId: this.ResumeId,
								...this.Dducation
							}).then(res => {
								if (res.Success) {
									this.Dducation.Id = res.Result.Id
									this.current++
								}
							})
					}

					console.log(this.Dducation)
				} else {
					if (this.Basics.CompanyName === '' || this.Basics.CompanyName === undefined) {
						uni.$u.toast("请输入公司名称")
						return
					}
					if (this.Basics.PositionName === '' || this.Basics.PositionName === undefined) {
						uni.$u.toast("请输入职位名称")
						return
					}
					if (this.Basics.Wage === '' || this.Basics.Wage === undefined) {
						uni.$u.toast("请输入当前月薪")
						return
					}
					if (this.Basics.PositionId === '' || this.Basics.PositionId === undefined) {
						uni.$u.toast("请选择职位类别")
						return
					}
					if (this.Basics.PositionId === '' || this.Basics.PositionId === undefined) {
						uni.$u.toast("请选择能力标签")
						return
					}
					//工作经历
					this.$http.huirc
						.resumeworkexpcr({
							ResumeId: this.ResumeId,
							...this.professional
						}).then(res => {
							if (res.Success) {
								uni.$u.toast("设置简历成功")
								uni.switchTab({
									url: "/pages/Home/index",
								});
							}
						})
				}
			},
			getValue(value) {
				if (this.current == 1) {
					this.$refs.JobIntention.getValue(value)
				} else {
					this.$refs.professional.getValue(value)
				}
			},
			guanjianci(val) {
				this.professional.Tags = val.map(value => {
					return {
						FullName: value.FullName
					}
				})
			}
		},
		components: {
			Basics,
			JobIntention,
			Dducation,
			professional
		},
		created() {
			const app = getApp()
			console.log(app.globalData);
		}
	}
</script>

<style lang="scss" scoped>
	.userMessage {
		height: 100vh;
		background-color: #fff;

		.headerTitle {
			color: #000000;
			font-size: 40rpx;
			font-family: PingFang SC-Bold;
			font-weight: 600;
			padding-left: 46rpx;
			margin-bottom: 16rpx;
		}

		.contentBox {
			margin-top: 32rpx;
			padding: 0rpx 40rpx;
		}
	}

	.bts {
		margin-top: 80rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		padding: 0rpx 10%;
	}
</style>